home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / rhstdlib.arc / GETC.ASM < prev    next >
Assembly Source File  |  1990-10-20  |  3KB  |  135 lines

  1. stdlib        segment    para public 'slcode'
  2.         assume    cs:stdlib
  3. ;
  4. ; Keyboard input routines:
  5. ;
  6. ;
  7. ; InpVector- Points at the current keyboard input routine.
  8. ;
  9. GetcAdrs    dd    sl_GetcStdIn
  10. GetcStkIndx    dw    0
  11. GetcStk        dd    16 dup (sl_GetcStdIn)
  12. GSIsize        =    $-GetcStk
  13. ;
  14. ;
  15. ;
  16.         public    sl_Getc
  17. sl_Getc        proc    far
  18.         jmp    dword ptr cs:GetcAdrs
  19. sl_Getc        endp
  20. ;
  21. ;
  22. ; SetInAdrs- Stores ES:DI into InpVector which sets the new keyboard vector.
  23. ;
  24.         public    sl_SetInAdrs
  25. sl_SetInAdrs    proc    far
  26.         mov    word ptr GetcAdrs, di
  27.         mov    word ptr GetcAdrs+2, es
  28.         ret
  29. sl_SetInAdrs    endp
  30. ;
  31. ;
  32. ; GetInAdrs-    Returns the address of the current output routine in ES:DI.
  33. ;
  34.         public    sl_GetInAdrs
  35. sl_GetInAdrs    proc    far
  36.         les    di, cs:GetcAdrs
  37.         ret
  38. sl_GetInAdrs    endp
  39. ;
  40. ;
  41. ;
  42. ; PushInAdrs-    Pushes the current input address onto the input stack
  43. ;        and then stores the address in es:di into the input address
  44. ;        pointer.  Returns carry clear if no problems.  Returns carry
  45. ;        set if there is an address stack overflow.  Does NOT modify
  46. ;        anything if the stack is full.
  47. ;
  48.         public    sl_PushInAdrs
  49. sl_PushInAdrs    proc    far
  50.         push    ax
  51.         push    di
  52.         cmp    cs:GetcStkIndx, GSIsize
  53.         jae    BadPush
  54.         mov    di, cs:GetcStkIndx
  55.         add    cs:GetcStkIndx, 4
  56.         mov    ax, word ptr cs:GetcAdrs
  57.         mov    word ptr cs:GetcStk[di], ax
  58.         mov    ax, word ptr cs:GetcAdrs+2
  59.         mov    word ptr cs:GetcStk+2[di], ax
  60.         pop    di
  61.         mov    word ptr cs:GetcAdrs, di
  62.         mov    word ptr cs:GetcAdrs+2, es
  63.         pop    ax
  64.         clc
  65.         ret
  66. ;
  67. BadPush:    pop    di
  68.         pop    ax
  69.         stc
  70.         ret
  71. sl_PushInAdrs    endp
  72. ;
  73. ;
  74. ; PopInAdrs-    Pops an input address off of the stack and stores it into
  75. ;        the GetcAdrs variable.
  76. ;
  77.         public    sl_PopInAdrs
  78. sl_PopInAdrs    proc    far
  79.         push    ax
  80.         mov    di, cs:GetcStkIndx
  81.         sub    di, 4
  82.         jns    GoodPop
  83. ;
  84. ; If this guy just went negative, set it to zero and push the address
  85. ; of the stdout routine onto the stack.
  86. ;
  87.         xor    di, di            
  88.         mov    word ptr cs:GetcStk, offset sl_GetcStdIn
  89.         mov    word ptr cs:GetcStk+2, seg sl_GetcStdIn
  90. ;
  91. GoodPop:    mov    cs:GetcStkIndx, di
  92.         mov    es, word ptr GetcAdrs+2
  93.         mov    ax, word ptr cs:GetcStk+2[di]
  94.         mov    word ptr cs:GetcAdrs+2, ax
  95.         mov    ax, word ptr cs:GetcStk[di]
  96.         xchg    word ptr cs:GetcAdrs, ax
  97.         mov    di, ax
  98.         pop    ax
  99.         ret
  100. sl_PopInAdrs    endp
  101. ;
  102. ;    
  103. ;
  104. ; GetcBIOS-     Reads a character from the keyboard using the BIOS routines.
  105. ;
  106.         public    sl_GetcBIOS
  107. sl_GetcBIOS    proc    far
  108.         mov    ah, 0
  109.         int    16h
  110.         ret        
  111. sl_GetcBIOS    endp
  112. ;
  113. ;
  114. ;
  115. ; GetcStdIn-     Reads a character from DOS' standard input.
  116. ;         
  117.         public    sl_GetcStdIn                                                
  118. sl_GetcStdIn    proc    far
  119.         mov    ah, 7
  120.         int    21h
  121.         mov    ah, 0
  122.         cmp    al, 0
  123.         jnz    DOS_GetcX
  124. ;
  125. ; If DOS returned zero, get scan code and return in AX
  126. ;
  127.         mov    ah, 7
  128.         int    21h
  129.         mov    ah, al
  130.         mov    al, 0
  131. DOS_GetcX:    ret
  132. sl_GetcStdIn    endp
  133. stdlib        ends
  134.         end
  135.